//
//  ViewController.m
//  TestOC
//
//  Created by China Dragon on 2023/8/25.
//

#import "ViewController.h"
#import "NetworkTools.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@", [NetworkTools sharedTools]);
    [self loadNetData];
  
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    // 测试单利
    NSLog(@"%@", [NetworkTools sharedTools]);
    
    /*
     2023-08-25 19:07:06.189759+0800 TestOC[29561:681055] <NetworkTools: 0x600000fc84a0>
     2023-08-25 19:07:20.795514+0800 TestOC[29561:681055] <NetworkTools: 0x600000fc84a0>
     2023-08-25 19:07:21.440427+0800 TestOC[29561:681055] <NetworkTools: 0x600000fc84a0>
     2023-08-25 19:07:21.840018+0800 TestOC[29561:681055] <NetworkTools: 0x600000fc84a0>
     
     内存地址是一样的，证明单例没有问题
     */
}

#pragma mark W网络请求
- (void)loadNetData {
    /*
     2023最新可用免费天气预报API接口
     https://blog.csdn.net/crazy_mi/article/details/127083547
     
     http://t.weather.itboy.net/api/weather/city/101030100
     
     https://www.baidu.com/
     
     */
    
    /*
    xcode7 开启要求服务器支持 https， 支持ssl 1.2 的版本
     这样更安全
     默认情况下不做任务设置，这时无法进行网络访问
     
     Xcode7.0之后, 设置允许HTTP请求
     https://blog.csdn.net/xbw12138/article/details/53046336
     
     xcode设置允许HTTP请求
     https://jingyan.baidu.com/article/f71d60375e83425bb641d1fe.html
     
     第一步: 点开info.plist文件-->点击箭头所指的+号
     第二步: 选中 App Transport Security Settings
     第三步:

     注意: 1. 先点击小箭头, 方向朝下.

              2. 然后点击+号

              3. 选中 Allow Arbitrary Loads
     第四步: 选中为:YES
     
     */
//    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com/"];
    NSURL *url = [NSURL URLWithString:@"http://t.weather.itboy.net/api/weather/city/101030100"];
    [[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
               
        //反序列化
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
        NSLog(@"响应结果 %@", result);
    }] resume];
    
}


@end
